package cn.liangxxhu.rocketmq.param;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> {
    // 数据列表
    private List<T> items;
    // 总条数
    private long total;
    // 当前页码
    private int pageNum;
    // 每页条数
    private int pageSize;
    // 总页数
    private int totalPages;
    
    public static <T> PageResult<T> of(List<T> items, long total, int pageNum, int pageSize) {
        int totalPages = (int) Math.ceil((double) total / pageSize);
        return new PageResult<>(items, total, pageNum, pageSize, totalPages);
    }
}
